package com.example.his.api.mis.service.impl;

import cn.hutool.core.map.MapUtil;
import com.example.his.api.common.PageUtils;
import com.example.his.api.db.dao.FlowRegulationDao;
import com.example.his.api.db.pojo.FlowRegulationEntiy;
import com.example.his.api.mis.service.FlowRegulationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@Service("FlowRegulationServiceImpl")
@Slf4j
public class FlowRegulationServiceImpl implements FlowRegulationService {
  
  @Resource
  private FlowRegulationDao flowRegulationDao;
  
  //  查询科室名称列表
  @Override
  public ArrayList <String> searchPlaceList() {
    return flowRegulationDao.searchPlaceList();
  }
  
  //  分页获取数据
  @Override
  public PageUtils searchByPage(Map param) {
    ArrayList list = new ArrayList <>();
    long count = flowRegulationDao.searchCount(param);
    if(count > 0) {
      list = flowRegulationDao.searchByPage(param);
    }
    
    int page = MapUtil.getInt(param, "page");
    int length = MapUtil.getInt(param, "length");
    PageUtils pageUtils = new PageUtils(list, count, page, length);
    return pageUtils;
  }
  
  @Override
  @Transactional
  public boolean insert(FlowRegulationEntiy flowRegulationEntiy) {
    int rows = flowRegulationDao.insert(flowRegulationEntiy);
    return rows == 1;
  }
  
  //  根据id查询碉流信息
  @Override
  public FlowRegulationEntiy searchById(int id) {
    FlowRegulationEntiy map = flowRegulationDao.searchById(id);
    return map;
  }
  
  @Override
  @Transactional
  public boolean update(Map map) {
    int rows = flowRegulationDao.update(map);
    return rows == 1;
  }
  
  @Override
  @Transactional
  public int deleteByIds(Integer[] ids) {
    int i = flowRegulationDao.deleteByIds(ids);
    return i;
  }
}
